//
//  COCOAFANMessageBoardView.m
//  CocoaFan
//
//  Created by Chen Xianan on 2009-03-28.
//  Copyright 2009 realazy.org. All rights reserved.
//

#import "COCOAFANMessageBoardView.h"
#import "YRKSpinningProgressIndicator.h"


@implementation COCOAFANMessageBoardView

- (void)awakeFromNib
{
	[indicator setForeColor:[NSColor whiteColor]];
	[indicator setBackColor:[NSColor clearColor]];
	[self setAlphaValue:0];
}

- (void)dealloc
{
	[timer invalidate];
	[super dealloc];
}

- (void)drawRect:(NSRect)rect {
	[[NSColor blackColor] set];
	[NSBezierPath fillRect:rect];
}

- (void)setMessage:(NSString *)message
			  type:(COCOAFAN_BOARDMESSAGE_TYPE)type
{
	NSColor *msgColor = type == COCOAFAN_BOARDMESSAGE_NORMAL ? [NSColor whiteColor] : [NSColor redColor];
	[textField setTextColor:msgColor];
	[textField setStringValue:message];
}

- (void)setMessage:(NSString *)message
{
	[self setMessage:message
				type:COCOAFAN_BOARDMESSAGE_NORMAL];
}

- (void)setWarningMessage:(NSString *)message
{
	[self setMessage:message
				type:COCOAFAN_BOARDMESSAGE_WARNING];
}

- (void)show
{
	[self setAlphaValue:0];
	[[self animator] setAlphaValue:.9];
}

- (void)showWithIndicator
{
	[indicator setHidden:NO];
	[indicator startAnimation:self];
	[self show];
}

- (void)hide
{
	[timer invalidate];
	[indicator stopAnimation:self];
	if (![indicator isHidden]) [indicator setHidden:YES];
	[[self animator] setAlphaValue:0];
}

- (void)scheduledHide:(NSTimeInterval)seconds
{
	[indicator stopAnimation:self];
	if (![indicator isHidden]) [indicator setHidden:YES];
	[timer invalidate];
	timer = [[NSTimer scheduledTimerWithTimeInterval:seconds
											  target:self
											selector:@selector(hide)
											userInfo:nil
											 repeats:NO] retain];
}

- (IBAction)hide:(id)sender
{
	[self hide];
}

@end
